package com.yehuishou.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.aspectj.apache.bcel.generic.InstructionTargeter;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yehuishou.dao.BidItemDao;
import com.yehuishou.dao.FileDao;
import com.yehuishou.pojo.BidItem;
import com.yehuishou.pojo.ImageFile;
import com.yehuishou.service.BidItemService;
import com.yehuishou.util.StringToDateUtil;


@Service
public class BidItemServiceImpl implements BidItemService {
    
	@Resource
	private BidItemDao bidItemDao;
	
	@Resource
	private FileDao fileDao;
	
	@Override
	public List<BidItem> getAllbiditem(BidItem bidItem) {
		
		return bidItemDao.getAllbiditem(bidItem);
	}


	@Override
	public void deleteBidItem(Integer bid) {
		bidItemDao.deleteBidItem(bid);
		
	}


	@Override
	public void addBidItem(BidItem biditem) {
		bidItemDao.insertBidItem(biditem);
		
	}


	
	//获取竞价商品的详情
	@Override
	public BidItem getBiditemDetial(Integer bid) {
		BidItem  bi =  bidItemDao.getOneByid(bid);
		String img="";
		if(bi!=null) {
			 img =bi.getImg_url();
		}
		if(img!=null&&img!="") {
		  String  img_url [] = img.split(";");
		  if(img_url.length>1) {
			ImageFile file =fileDao.getOneImageByid(Integer.parseInt(img_url[1]));
			bi.setImg_url(file.getFilePath());
		  }
		}
		return bi; 
	}
	
	@Override
	public boolean checkBidItemExsit(BidItem biditem) {
		
		BidItem biditem2 =bidItemDao.checkBidItemExsit(biditem);
		boolean flag = false;
				
		if(biditem2!=null) {
			
			flag=true;
			
		}			
		return  flag;
	}

     
	
	//修改价格信息
	@Override
	public void updateBidItemByid(BidItem bid) {
		bidItemDao.updateBiditem(bid);
		
	}

    //修改更多信息
	@Override
	public void updateBidItemAll(BidItem bid) {
		bidItemDao.updateBidItemAll(bid);
		
	}


	@Override
	public void deleteBidItems(Integer[] bids) {
		bidItemDao.deleteBidItems(bids);
		
	}



	

}
